home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!tektronix!tekgen!tekred!games-request
- From: games-request@tekred.TEK.COM
- Newsgroups: comp.sources.games
- Subject: v02i099: puzzletool - a puzzle game for Sun workstations
- Message-ID: <1881@tekred.TEK.COM>
- Date: 1 Dec 87 01:26:35 GMT
- Sender: billr@tekred.TEK.COM
- Lines: 572
- Approved: billr@tekred.TEK.COM
-
- Submitted by: Jiang-Hsing Chu <jchu@mimsy.umd.edu>
- Comp.sources.games: Volume 2, Issue 99
- Archive-name: puzzletool
-
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: README Makefile puzzletool.c puzzletool.h
- # Wrapped by billr@tekred on Mon Nov 30 17:25:15 1987
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f README -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"README\"
- else
- echo shar: Extracting \"README\" \(700 characters\)
- sed "s/^X//" >README <<'END_OF_README'
- XThe goal of this game is to move down the largest piece to the bottom in
- Xminimal number of movements. It is known that the puzzle can be solved in
- X86 movements. To move a piece, point it by the mouse and press the left
- Xbutton, hold the left button until you move the mouse to an adjacent empty
- Xsquare. Use the middle button to close the frame into the icon format. If
- Xyou want to quit, press the right button.
- X
- XThe game works on SUN workstation only. It is tested in SUN 3/50.
- XSome ideas on setting up the interface were borrowed from the calctool program
- Xby Rich Burridge. Have fun.
- X Jiang-Hsing Chu
- X jchu@mimsy.umd.edu
- END_OF_README
- if test 700 -ne `wc -c <README`; then
- echo shar: \"README\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f Makefile -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"Makefile\"
- else
- echo shar: Extracting \"Makefile\" \(146 characters\)
- sed "s/^X//" >Makefile <<'END_OF_Makefile'
- X
- Xpuzzletool: puzzletool.o
- X cc -g -o puzzletool puzzletool.o -lsuntool -lsunwindow -lpixrect
- X
- Xpuzzletool.o: puzzletool.c puzzletool.h
- END_OF_Makefile
- if test 146 -ne `wc -c <Makefile`; then
- echo shar: \"Makefile\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f puzzletool.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"puzzletool.c\"
- else
- echo shar: Extracting \"puzzletool.c\" \(19087 characters\)
- sed "s/^X//" >puzzletool.c <<'END_OF_puzzletool.c'
- X#include "puzzletool.h"
- X
- Xvoid canvas_proc() ;
- X
- XCanvas canvas, rcanvas ;
- XCursor main_cursor ;
- XEvent event ;
- XFrame frame ;
- XIcon puzzletool_icon ;
- XPanel panel ;
- XPanel_item display_item ;
- Xstruct Pixfont *nfont ;
- XPixwin *cpw ;
- X
- Xshort piece0_image[] = {
- X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
- X */
- X 0x0000,0x0000,0x0000,0x0000,0x7FFF,0xFFFE,0x0000,0x0000,
- X 0x7BBB,0xBBBA,0x0000,0x0000,0x6EEE,0xEEEE,0x0000,0x0000,
- X 0x7777,0x7776,0x0000,0x0000,0x5DDD,0xDDDE,0x0000,0x0000,
- X 0x7BBB,0xBBBA,0x0000,0x0000,0x6EEE,0xEEEE,0x0000,0x0000,
- X 0x7777,0x7776,0x0000,0x0000,0x5DDD,0xDDDE,0x0000,0x0000,
- X 0x7BBB,0xBBBA,0x0000,0x0000,0x6EEE,0xEEEE,0x0000,0x0000,
- X 0x7777,0x7776,0x0000,0x0000,0x5DDD,0xDDDE,0x0000,0x0000,
- X 0x7BBB,0xBBBA,0x0000,0x0000,0x6EEE,0xEEEE,0x0000,0x0000,
- X 0x7777,0x7776,0x0000,0x0000,0x5DDD,0xDDDE,0x0000,0x0000,
- X 0x7BBB,0xBBBA,0x0000,0x0000,0x6EEE,0xEEEE,0x0000,0x0000,
- X 0x7777,0x7776,0x0000,0x0000,0x5DDD,0xDDDE,0x0000,0x0000,
- X 0x7BBB,0xBBBA,0x0000,0x0000,0x6EEE,0xEEEE,0x0000,0x0000,
- X 0x7777,0x7776,0x0000,0x0000,0x5DDD,0xDDDE,0x0000,0x0000,
- X 0x7BBB,0xBBBA,0x0000,0x0000,0x6EEE,0xEEEE,0x0000,0x0000,
- X 0x7777,0x7776,0x0000,0x0000,0x5DDD,0xDDDE,0x0000,0x0000,
- X 0x7FFF,0xFFFE,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
- X} ;
- Xmpr_static(piece0_pr,64,64,1,piece0_image) ;
- X
- Xshort piece1_image[] = {
- X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
- X */
- X 0x0000,0x0000,0x0000,0x0000,0x7FFF,0xFFFE,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x6AAA,0xAAAA,0x0000,0x0000,0x5555,0x5556,0x0000,0x0000,
- X 0x7FFF,0xFFFE,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
- X} ;
- Xmpr_static(piece1_pr,64,64,1,piece1_image) ;
- X
- Xshort piece2_image[] = {
- X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
- X */
- X 0x0000,0x0000,0x0000,0x0000,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x6AAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5556,
- X 0x7FFF,0xFFFF,0xFFFF,0xFFFE,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
- X} ;
- Xmpr_static(piece2_pr,64,64,1,piece2_image) ;
- X
- Xshort piece3_image[] = {
- X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
- X */
- X 0x0000,0x0000,0x0000,0x0000,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x4444,0x4444,0x4444,0x4446,0x5111,0x1111,0x1111,0x1112,
- X 0x4888,0x8888,0x8888,0x888A,0x6222,0x2222,0x2222,0x2222,
- X 0x7FFF,0xFFFF,0xFFFF,0xFFFE,0x0000,0x0000,0x0000,0x0000
- X} ;
- Xmpr_static(piece3_pr,64,64,1,piece3_image) ;
- X
- Xshort icon_image[] = {
- X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
- X */
- X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xC000,0xFF00,0x0007,0xC003,0xC003,0xFF80,0x000F,0xE003,
- X 0xC007,0x83C0,0x001F,0xF003,0xC00E,0x00E0,0x003F,0xF803,
- X 0xC018,0x0070,0x003F,0xF803,0xC038,0x0038,0x003F,0xF803,
- X 0xC030,0x0018,0x003F,0xF803,0xC070,0x001C,0x003F,0xF803,
- X 0xC060,0x000C,0x001F,0xF003,0xC000,0x000C,0x001F,0xF003,
- X 0xC000,0x000C,0x001F,0xF003,0xC000,0x000C,0x001F,0xE003,
- X 0xC000,0x000C,0x001F,0xE003,0xC000,0x001C,0x000F,0xE003,
- X 0xC000,0x0018,0x000F,0xE003,0xC000,0x0038,0x000F,0xE003,
- X 0xC000,0x0070,0x000F,0xC003,0xC000,0x00E0,0x000F,0xC003,
- X 0xC000,0x03C0,0x000F,0xC003,0xC000,0x3F80,0x000F,0xC003,
- X 0xC000,0x3E00,0x000F,0xC003,0xC000,0x3000,0x0007,0x8003,
- X 0xC000,0x3000,0x0007,0x8003,0xC000,0x3000,0x0007,0x8003,
- X 0xC000,0x3000,0x0007,0x8003,0xC000,0x3000,0x0007,0x8003,
- X 0xC000,0x3000,0x0007,0x0003,0xC000,0x3000,0x0007,0x0003,
- X 0xC000,0x3000,0x0007,0x0003,0xC000,0x3000,0x0003,0x0003,
- X 0xC000,0x3000,0x0003,0x0003,0xC000,0x3000,0x0002,0x0003,
- X 0xC000,0x3000,0x0002,0x0003,0xC000,0x3000,0x0002,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x3800,0x0007,0x0003,
- X 0xC000,0x7C00,0x001F,0xC003,0xC000,0xFE00,0x001F,0xC003,
- X 0xC000,0xFE00,0x003F,0xE003,0xC000,0xFE00,0x003F,0xE003,
- X 0xC000,0x7C00,0x003F,0xE003,0xC000,0x3800,0x001F,0xC003,
- X 0xC000,0x0000,0x001F,0xC003,0xC000,0x0000,0x0007,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
- X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF
- X} ;
- Xmpr_static(icon_pixrect,64,64,1,icon_image) ;
- X
- Xint ncolumn,column ; /* Column number of key pressed. */
- Xint m,n ; /* mouse and index */
- Xint nrow,row ; /* Row number of key pressed. */
- Xint step=0;
- X
- X
- Xint board[7][6]= {
- X {-2,-2,-2,-2,-2,-2}, {-2,4,9,9,5,-2}, {-2,4,9,9,5,-2},
- X {-2,6,8,8,7,-2}, {-2,6,0,1,7,-2},
- X {-2,-1,2,3,-1,-2}, {-2,-2,-2,-2,-2,-2}
- X};
- Xint pieces[10][5] = {
- X {0,2,4,1,1}, {0,3,4,1,1}, {0,2,5,1,1}, {0,3,5,1,1},
- X {1,1,1,1,2}, {1,4,1,1,2}, {1,1,3,1,2}, {1,4,3,1,2},
- X {2,2,3,2,1},{3,2,1,2,2}
- X} ;
- X
- Xchar display[MAXLINE] ; /* Current calculator display. */
- X
- X
- Xmain(argc,argv)
- Xint argc ;
- Xchar *argv[] ;
- X
- X{
- X nfont = pf_open(NORMALFONT) ; /* Open normal sized font. */
- X puzzletool_icon = icon_create(ICON_WIDTH,64,
- X ICON_IMAGE,&icon_pixrect,
- X 0) ;
- X
- X frame = window_create((Window) 0, FRAME,
- X FRAME_ICON, puzzletool_icon,
- X FRAME_SHOW_LABEL, FALSE,
- X FRAME_SUBWINDOWS_ADJUSTABLE, FALSE,
- X FRAME_NO_CONFIRM, FALSE,
- X WIN_TOP_MARGIN, DISPLAY,
- X WIN_ROW_HEIGHT, PIECE_H,
- X WIN_COLUMN_WIDTH, PIECE_W,
- X WIN_ROWS, PIECE_ROWS,
- X WIN_COLUMNS, PIECE_COLS,
- X FRAME_ARGS, argc,argv,
- X 0) ;
- X
- X panel = window_create(frame, PANEL,
- X WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS, 0,
- X WIN_HEIGHT, DISPLAY,
- X 0) ;
- X
- X canvas = window_create(frame,CANVAS,
- X WIN_BELOW,panel,
- X WIN_WIDTH,TOTAL_WIDTH,
- X WIN_HEIGHT,TOTAL_HEIGHT,
- X WIN_FONT,nfont,
- X WIN_EVENT_PROC,canvas_proc,
- X 0) ;
- X WINDOW_SET(canvas,WIN_CONSUME_KBD_EVENT,WIN_ASCII_EVENTS,0) ;
- X
- X display_item = panel_create_item(panel,PANEL_MESSAGE,
- X PANEL_LABEL_X,10,
- X PANEL_LABEL_Y,DISPLAY-15,
- X PANEL_LABEL_FONT,nfont,
- X PANEL_LABEL_STRING,"",
- X 0) ;
- X cpw = canvas_pixwin(canvas) ;
- X main_cursor = window_get(canvas,WIN_CURSOR) ;
- X
- X make_canvas() ; /* Draw the calculators pieces. */
- X window_fit(frame) ;
- X window_main_loop(frame) ;
- X exit(0) ;
- X}
- X
- X/*ARGSUSED*/
- Xstatic void
- Xcanvas_proc(win,event,arg)
- XCanvas win ;
- XEvent *event ;
- Xcaddr_t arg ;
- X
- X{
- X if (event_is_button(event) && event_is_down(event))
- X {
- X switch (event_id(event))
- X {
- X case MS_LEFT : column = event_x(event) / PIECE_W ;
- X row = event_y(event) / PIECE_H ;
- X n = board[row+1][column+1] ; m=0;
- X return;
- X case MS_MIDDLE : WINDOW_SET(frame,FRAME_CLOSED,TRUE,0);
- X return;
- X case MS_RIGHT : WINDOW_DESTROY(frame);
- X default: return ;
- X }
- X }
- X if (event_is_button(event) && event_is_up(event) && n>=0)
- X {
- X switch (event_id(event))
- X {
- X case MS_LEFT : ncolumn = event_x(event) / PIECE_W;
- X nrow = event_y(event) / PIECE_H ;
- X if(board[nrow+1][ncolumn+1]!=-1)return ;
- X if(ncolumn>column) m=0;
- X if(nrow<row)m=1;
- X if(ncolumn<column) m=2;
- X if(nrow>row)m=3;
- X do_move();
- X case MS_MIDDLE :
- X case MS_RIGHT :
- X default: return ;
- X }
- X }
- X return ;
- X
- X}
- X
- Xdisplay_test(display) /* Output result to calculator display. */
- Xchar display[MAXLINE];
- X{
- X PANEL_SET(display_item,PANEL_LABEL_STRING,display,0) ;
- X}
- X
- Xmake_canvas()
- X{
- X int n,x ;
- X char pstr[10] ;
- X
- X pw_writebackground(cpw,0,0,TOTAL_WIDTH,TOTAL_HEIGHT,PIX_CLR) ;
- X for(n=0;n<4;++n)
- X pw_write(cpw,(pieces[n][PX]-1)*PIECE_W, (pieces[n][PY]-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece0_pr,0,0) ;
- X for(n=4;n<8;++n)
- X pw_write(cpw,(pieces[n][PX]-1)*PIECE_W, (pieces[n][PY]-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece1_pr,0,0) ;
- X n=8;
- X pw_write(cpw,(pieces[n][PX]-1)*PIECE_W, (pieces[n][PY]-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece2_pr,0,0) ;
- X n=9;
- X pw_write(cpw,(pieces[n][PX]-1)*PIECE_W, (pieces[n][PY]-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece3_pr,0,0) ;
- X}
- X
- Xdo_move()
- X{
- X int ox,oy,nx,ny;
- X
- X ox=pieces[n][PX];
- X oy=pieces[n][PY];
- X switch(n){
- X case 0:
- X case 1:
- X case 2:
- X case 3: switch(m){
- X case 0: if(board[ny=oy][nx=ox+1]==-1)break;
- X return;
- X case 1: if(board[ny=oy-1][nx=ox]==-1)break;
- X return;
- X case 2: if(board[ny=oy][nx=ox-1]==-1)break;
- X return;
- X case 3: if(board[ny=oy+1][nx=ox]==-1)break;
- X return;
- X }
- X break;
- X case 4:
- X case 5:
- X case 6:
- X case 7: switch(m){
- X case 0: if(board[oy][ox+1]==-1&&board[oy+1][ox+1]==-1){nx=ox+1;ny=oy;break;}
- X return;
- X case 1: if(board[oy-1][ox]==-1){nx=ox;ny=oy-1;break;}
- X return;
- X case 2: if(board[oy][ox-1]==-1&&board[oy+1][ox-1]==-1){nx=ox-1;ny=oy;break;}
- X return;
- X case 3: if(board[oy+2][ox]==-1){nx=ox;ny=oy+1;break;}
- X return;
- X }
- X break;
- X case 8: switch(m){
- X case 0: if(board[oy][ox+2]==-1){nx=ox+1;ny=oy;break;}
- X return;
- X case 1: if(board[oy-1][ox]==-1&&board[oy-1][ox+1]==-1){nx=ox;ny=oy-1;break;}
- X return;
- X case 2: if(board[oy][ox-1]==-1){nx=ox-1;ny=oy;break;}
- X return;
- X case 3: if(board[oy+1][ox]==-1&&board[oy+1][ox+1]==-1){nx=ox;ny=oy+1;break;}
- X return;
- X }
- X break;
- X case 9: switch(m){
- X case 0: if(board[oy][ox+2]==-1&&board[oy+1][ox+2]==-1){nx=ox+1;ny=oy;break;}
- X return;
- X case 1: if(board[oy-1][ox]==-1&&board[oy-1][ox+1]==-1){nx=ox;ny=oy-1;break;}
- X return;
- X case 2: if(board[oy][ox-1]==-1&&board[oy+1][ox-1]==-1){nx=ox-1;ny=oy;break;}
- X return;
- X case 3: if(board[oy+2][ox]==-1&&board[oy+2][ox+1]==-1){nx=ox;ny=oy+1;break;}
- X return;
- X }
- X break;
- X
- X }
- X itos(++step,display);
- X display_test(display);
- X pieces[n][PX]=nx;pieces[n][PY]=ny;
- X switch(n){
- X case 0:
- X case 1:
- X case 2:
- X case 3: board[oy][ox]= -1;
- X board[ny][nx]=n;
- X pw_writebackground(cpw,(ox-1)*PIECE_W,(oy-1)*PIECE_H,pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_CLR);
- X pw_write(cpw,(nx-1)*PIECE_W, (ny-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece0_pr,0,0) ;
- X break;
- X case 4:
- X case 5:
- X case 6:
- X case 7: board[oy][ox]=board[oy+1][ox]= -1;
- X board[ny][nx]=board[ny+1][nx]=n;
- X pw_writebackground(cpw,(ox-1)*PIECE_W,(oy-1)*PIECE_H,pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_CLR);
- X pw_write(cpw,(nx-1)*PIECE_W, (ny-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece1_pr,0,0) ;
- X break;
- X case 8: board[oy][ox]=board[oy][ox+1]= -1;
- X board[ny][nx]=board[ny][nx+1]=n;
- X pw_writebackground(cpw,(ox-1)*PIECE_W,(oy-1)*PIECE_H,pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_CLR);
- X pw_write(cpw,(nx-1)*PIECE_W, (ny-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece2_pr,0,0) ;
- X break;
- X case 9: board[oy][ox]=board[oy][ox+1]=board[oy+1][ox]=board[oy+1][ox+1]= -1;
- X board[ny][nx]=board[ny][nx+1]=board[ny+1][nx]=board[ny+1][nx+1]=n;
- X pw_writebackground(cpw,(ox-1)*PIECE_W,(oy-1)*PIECE_H,pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_CLR);
- X pw_write(cpw,(nx-1)*PIECE_W, (ny-1)*PIECE_H, pieces[n][PDX]*PIECE_W,pieces[n][PDY]*PIECE_H,PIX_SRC,&piece3_pr,0,0) ;
- X break;
- X }
- X}
- X
- Xitos(i,c)
- Xint i;
- Xchar *c;
- X
- X{ int j;
- X char t;
- X
- X c[0]='\0';
- X for(j=1;i>0;j++){
- X c[j]=i%10+'0';
- X i/=10;
- X }
- X for(i=0;i<j/2;++i){
- X t=c[i];
- X c[i]=c[j-1-i];
- X c[j-1-i]=t;
- X }
- X}
- END_OF_puzzletool.c
- if test 19087 -ne `wc -c <puzzletool.c`; then
- echo shar: \"puzzletool.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f puzzletool.h -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"puzzletool.h\"
- else
- echo shar: Extracting \"puzzletool.h\" \(1527 characters\)
- sed "s/^X//" >puzzletool.h <<'END_OF_puzzletool.h'
- X
- X#include <stdio.h>
- X#include <strings.h>
- X#include <ctype.h>
- X
- X#include <suntool/sunview.h>
- X#include <suntool/canvas.h>
- X#include <suntool/panel.h>
- X
- Xchar *sprintf() ;
- X
- X#define FGETS (void) fgets /* To make lint happy. */
- X#define FPRINTF (void) fprintf
- X#define IOCTL (void) ioctl
- X#define PANEL_SET (void) panel_set
- X#define READ (void) read
- X#define SPRINTF (void) sprintf
- X#define SSCANF (void) sscanf
- X#define STRCAT (void) strcat
- X#define STRCPY (void) strcpy
- X#define STRNCAT (void) strncat
- X#define STRNCPY (void) strncpy
- X#define WINDOW_DESTROY (void) window_destroy
- X#define WINDOW_READ_EVENT (void) window_read_event
- X#define WINDOW_SET (void) window_set
- X
- X#define NORMALFONT "/usr/lib/fonts/fixedwidthfonts/screen.r.12"
- X
- X#define PIECE_COLS 4 /* No of columns of pieces. */
- X#define PIECE_H 32 /* Number of pixels for height. */
- X#define PIECE_ROWS 5 /* No of rows of pieces. */
- X#define PIECE_W 32 /* No of pixels for width. */
- X#define DISPLAY 30 /* Calculators numerical display. */
- X
- X#define EQUAL !strcmp /* For character comparisons. */
- X#define MAXLINE 80 /* Length of character strings. */
- X#define TOTAL_HEIGHT (PIECE_ROWS * PIECE_H)
- X#define TOTAL_WIDTH (PIECE_COLS * PIECE_W)
- X#define PTYPE 0
- X#define PX 1
- X#define PY 2
- X#define PDX 3
- X#define PDY 4
- END_OF_puzzletool.h
- if test 1527 -ne `wc -c <puzzletool.h`; then
- echo shar: \"puzzletool.h\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- echo shar: End of shell archive.
- exit 0
-